package com.gxa.service.impl;

import com.gxa.pojo.Agreement;
import com.gxa.dao.AgreementDao;
import com.gxa.service.AgreementService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Agreement)表服务实现类
 *
 * @author makejava
 * @since 2022-09-01 12:37:55
 */
@Service("agreementService")
public class AgreementServiceImpl implements AgreementService {
    @Resource
    private AgreementDao agreementDao;

    /**
     * 通过ID查询单条数据
     *
     * @param agreement 主键
     * @return 实例对象
     */
    @Override
    public List<Agreement> query(Agreement agreement) {
        return this.agreementDao.query(agreement);
    }

    /**
     * 分页查询
     *
     * @param agreement   筛选条件
     * @return 查询结果
     */
    @Override
    public List<Agreement> queryByPage(Agreement agreement,int page,int size) {
        return this.agreementDao.queryAllByLimit(agreement,page,size);
    }

    /**
     * 新增数据
     *
     * @param agreement 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(Agreement agreement) {
        return this.agreementDao.insert(agreement);
    }

    /**
     * 修改数据
     *
     * @param agreement 实例对象
     * @return 实例对象
     */
    @Override
    public Agreement update(Agreement agreement) {
        if (this.agreementDao.update(agreement) > 0) {
            return this.agreementDao.query(agreement).get(0);
        } else {
            return null;
        }
    }

    /**
     * 通过主键删除数据
     *
     * @param agreement 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Agreement agreement) {
        Integer id = this.agreementDao.query(agreement).get(0).getAgreementId();
        return this.agreementDao.deleteById(id) > 0;
    }
}
